package com.qzboot.basic.service.config;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis增强插件配置
 *
 * @author zengzhihong
 * @date 2019/04/17
 */
@Configuration
public class MybatisPlusConfig {


    /**
     * 分页插件，自动识别数据库类型
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * 乐观锁插件
     *
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }


    /**
     * 公共字段自动填充
     */
    @Bean
    public GlobalConfig globalConfiguration(MybatisPlusMetaObjectHandler mybatisPlusMetaObjectHandler) {
        GlobalConfig gc = new GlobalConfig();
        gc.setMetaObjectHandler(mybatisPlusMetaObjectHandler);
        return gc;
    }
}
